package com.geen.tuoke.network.api

import com.geen.tuoke.UrlManger
import com.geen.tuoke.bean.*
import com.geen.tuoke.bean.request.*
import com.geen.tuoke.network.utils.CacheUtil

import com.seeway.wms.network.api.ApiResponse
import okhttp3.MultipartBody
import retrofit2.http.*


interface ApiService {

    companion object {
        //        const val SERVER_URL = "http://192.168.5.60:8788/"
        var SERVER_URL = UrlManger.getApiUrl()
    }

    /***
     * 刷新token
     */
    @POST("mobile/user/refreshToken")
    suspend fun refreshToken(): ApiResponse<LoginInfo>

    /***
     * 表单登录
     * @param map Map<String, [@kotlin.jvm.JvmSuppressWildcards] Any>
     * @return ApiResponse<Any>
     */
    @FormUrlEncoded
    @POST("login")
    suspend fun login(@FieldMap map: Map<String, @JvmSuppressWildcards Any>): ApiResponse<LoginInfo>

    /***
     * 获取任务列表
     *
     */
    @GET("mobile/task/list/{current}/{size}")
    suspend fun getPhoneTask(
        @Path("current") pageNo: Int,
        @Path("size") pageSize: Int
    ): ApiResponse<DataPage<TaskInfo>>


    /***
     * 获取任务详情
     *
     */
    @GET("/mobile/task/detail/{current}/{size}")
    suspend fun getPhoneTaskDetailById(
        @Path("current") pageNo: Int = 1,
        @Path("size") pageSize: Int = 1000,
        @Query("taskId") taskId: Int,
    ): ApiResponse<DataPage<TaskDetailInfo>>

    /***
     * /mobile/task/update/interval
    更新任务时间间隔,content-type:application/x-www-form-urlencoded
     *
     */
    @FormUrlEncoded
    @POST("/mobile/task/update/interval")
    suspend fun updatePhoneTaskInterval(
        @Field("interval") interval: Int,
        @Field("taskId") taskId: Int,
    ): ApiResponse<Any?>

    /***
     * 添加任务条目,content-type:application/json
     *
     */
    @POST("/mobile/task/item/add")
    suspend fun addPhoneTask(
        @Body map: AddTaskRequest,
    ): ApiResponse<Any?>

    /***
     * 重建任务 ,content-type:application/json
     *
     */
    @POST("/mobile/task/recreate")
    suspend fun recreatePhoneTask(
        @Body map: RecreateTaskRequest,
    ): ApiResponse<Any?>


    //删除任务
    @FormUrlEncoded
    @POST("/mobile/task/item/delete")
    suspend fun deletePhoneTask(
        @Field("itemId") itemId: Int,
        @Field("taskId") taskId: Int,
    ): ApiResponse<Any?>


    /***
     * 我的信息
     * mobile/user/{mobile}
     */
    @GET("mobile/user")
    suspend fun getMeInfo(): ApiResponse<UserInfo>


    /***
     * 搜索任务
     */
    @Headers("Content-type:application/json")
    @POST("mobile/task/item/query/{current}/{size}")
    suspend fun phoneTaskQuery(
        @Path("current") pageNo: Int,
        @Path("size") pageSize: Int,
        @Body request: PhoneTaskRequest
    ): ApiResponse<DataPage<SearchTaskInfo>>

    /***
     * 上传文件
     * /mobile/task/uploadCreateTask
     */
    @Multipart
    @POST("mobile/task/uploadCreateTask")
    suspend fun uploadFile(
        @Query("name") name: String,
        @Part file: MultipartBody.Part
    ): ApiResponse<Any>


    /**
     * 添加客户,content-type:application/json
     */
    @POST("/mobile/client/add")
    suspend fun addCustomer(@Body customerInfo: CustomerInfo): ApiResponse<String?>

    /**
     *  更新客户信息,
     */
    @PUT("/mobile/client")
    suspend fun updateCustomer(@Body customerInfo: CustomerInfo): ApiResponse<String?>

    /**
     * 查询客户
     */
    @Headers("Content-type:application/json")
    @POST("/mobile/client/list/{current}/{size}")
    suspend fun getCustomerList(
        @Body query: QueryCustomerModel,
        @Path("current") current: Int = 1,
        @Path("size") size: Int = 100
    ): ApiResponse<DataPage<CustomerInfo>>


    /**
     * 添加标签
     */
    @FormUrlEncoded
    @POST("/mobile/label/add")
    suspend fun addLabel(
        @Field("name") name: String,
        @Field("iid") iid: Int = CacheUtil.getUserInfo()?.industryId ?: 0
    ): ApiResponse<Label>

    /**
     * 添加标签
     */
    @GET("/mobile/label")
    suspend fun getLabelList(): ApiResponse<List<Label>>

    /***
     * 拨打电话
     * /mobile/task/callout
     */
    @FormUrlEncoded
    @POST("/mobile/task/callout")
    suspend fun callout(
        @Field("itemId") itemId: String = "",
        @Field("taskId") taskId: String = "",
        @Field("mobile") mobile: String
    ): ApiResponse<String>

    /***
     * 上传头像
     * /mobile/user/avater
     */
    @Multipart
    @POST("mobile/user/avater")
    suspend fun upLoadAvatar(
        @Part file: MultipartBody.Part
    ): ApiResponse<Any?>

    /***
     * 根据客户ID 获取客户信息
     * /mobile/client/get/{id}
     */
    @GET("mobile/client/get/{id}")
    suspend fun getCustomInfo(
        @Path("id") id: String
    ): ApiResponse<CustomerInfo>

    /***
     * 获取支付金额列表
     * /agent/user/pay/money/type
     */
    @GET("agent/user/pay/money/type")
    suspend fun getPayMoneyList(): ApiResponse<MutableList<PayMoneyInfo>>

    /***
     * 更新任务
     * /mobile/task/item/update
     */
    @Headers("Content-type:application/json")
    @PUT("mobile/task/item/update")
    suspend fun updateTask( @Body query: UpdateTaskRequest):ApiResponse<Any?>

    @Headers("Content-type:application/json")
    @PUT("mobile/task/item/update")
    suspend fun updateTask( @Body query: UpdateTaskMobile):ApiResponse<Any?>

    /***
     * 更新手动拨号任务
     * /mobile/task/item/update
     */
    @Headers("Content-type:application/json")
    @POST("mobile/task/manualDial")
    suspend fun updatePhoneTask( @Body query: UpdatePhoneTaskRequest):ApiResponse<Any?>

    /***
     * 根据手机号码获取用户信息
     * /mobile/client/mobile/{mobile}
     */
    @GET("mobile/client/mobile/{mobile}")
    suspend fun getCustomInfoByMobile(
        @Path("mobile") mobile: String
    ): ApiResponse<CustomerInfo?>
}